import { deleteByPrimaryKeyForProMenu, selectByPrimaryKeyForProMenu, insertForProMenu, updateForProMenu, deleteByMapForProMenu,updateByMapForProMenu, getOneForProMenu,getAllForProMenu,queryPageForProMenu, countForProMenu, insertBatchForProMenu, deleteBatchForProMenu,updateBatchForProMenu,getProMenuTreeByLevelCode } from '@/services/system/api_promenu';

export default {
    namespace: 'promenu',

    state: {
        data: {
            list: [],
            pagination: {},
        },
        menu:{
        	list:[],
        },
    },

    effects: {
            *delete_by_primarykey_for_promenu({ payload,callback }, { call, put }) {
                const response = yield call(deleteByPrimaryKeyForProMenu, payload);
				
				const newPayload = {currentPage: payload.currentPage,pageSize: payload.pageSize};
                const responsedata = yield call(queryPageForProMenu, newPayload);
                yield put({
	                type: 'queryPageForProMenu',
	                payload: responsedata,
                });
                
				if (callback) callback(response);

            },
            *select_by_primarykey_for_promenu({ payload, callback }, { call, put }) {
                const response = yield call(selectByPrimaryKeyForProMenu, payload);
                yield put({
                    type: 'selectByPrimaryKeyForProMenu',
                    payload: response,
                });

                if (callback) callback();
            },
            *insert_for_promenu({ payload, callback }, { call, put }) {
                const response = yield call(insertForProMenu, payload);


                const responsedata = yield call(queryPageForProMenu, {});
                yield put({
	                type: 'queryPageForProMenu',
	                payload: responsedata,
                });

                if (callback) callback(response);
            },
            *update_for_promenu({ payload, callback }, { call, put }) {
                const response = yield call(updateForProMenu, payload);

				const newPayload = {currentPage: payload.currentPage,pageSize: payload.pageSize};
                const responsedata = yield call(queryPageForProMenu, newPayload);
                yield put({
	                type: 'queryPageForProMenu',
	                payload: responsedata,
                });

                if (callback) callback(response);
            },
            *delete_by_map_for_promenu({ payload, callback }, { call, put }) {
                const response = yield call(deleteByMapForProMenu, payload);
                yield put({
                    type: 'deleteByMapForProMenu',
                    payload: response,
                });


                const responsedata = yield call(queryPageForProMenu, {});
                yield put({
                type: 'queryPageForProMenu',
                payload: responsedata,
                });

                if (callback) callback();
            },
            *update_by_map_for_promenu({ payload, callback }, { call, put }) {
                const response = yield call(updateByMapForProMenu, payload);
                yield put({
                    type: 'updateByMapForProMenu',
                    payload: response,
                });


                const responsedata = yield call(queryPageForProMenu, {});
                yield put({
                type: 'queryPageForProMenu',
                payload: responsedata,
                });

                if (callback) callback();
            },
            *get_one_for_promenu({ payload, callback }, { call, put }) {
                const response = yield call(getOneForProMenu, payload);
                yield put({
                    type: 'getOneForProMenu',
                    payload: response,
                });

                if (callback) callback();
            },
            *get_all_for_promenu({ payload, callback }, { call, put }) {
                const response = yield call(getAllForProMenu, payload);
                yield put({
                    type: 'getAllForProMenu',
                    payload: response,
                });
                if (callback) callback();
            },
            *query_page_for_promenu({ payload, callback }, { call, put }) {
                const response = yield call(queryPageForProMenu, payload);
                yield put({
                    type: 'queryPageForProMenu',
                    payload: response,
                });

                if (callback) callback();
            },
            *count_for_promenu({ payload, callback }, { call, put }) {
                const response = yield call(countForProMenu, payload);
                yield put({
                    type: 'countForProMenu',
                    payload: response,
                });

                if (callback) callback();
            },
            *insert_batch_for_promenu({ payload, callback }, { call, put }) {
                const response = yield call(insertBatchForProMenu, payload);
                yield put({
                    type: 'insertBatchForProMenu',
                    payload: response,
                });


                const responsedata = yield call(queryPageForProMenu, {});
                yield put({
                type: 'queryPageForProMenu',
                payload: responsedata,
                });


                if (callback) callback();
            },
            *delete_batch_for_promenu({ payload, callback }, { call, put }) {
                const response = yield call(deleteBatchForProMenu, payload);
                yield put({
                    type: 'deleteBatchForProMenu',
                    payload: response,
                });

                const responsedata = yield call(queryPageForProMenu, {});
                yield put({
                type: 'queryPageForProMenu',
                payload: responsedata,
                });

                if (callback) callback();
            },
            *update_batch_for_promenu({ payload, callback }, { call, put }) {
                const response = yield call(updateBatchForProMenu, payload);
                yield put({
                    type: 'updateBatchForProMenu',
                    payload: response,
                });

                const responsedata = yield call(queryPageForProMenu, {});
                yield put({
	                type: 'queryPageForProMenu',
	                payload: responsedata,
                });

                if (callback) callback();
            },
            *get_promenutree_by_levelcode({ payload, callback }, { call, put }) {
                const response = yield call(getProMenuTreeByLevelCode, payload);
                yield put({
                    type: 'getProMenuTreeByLevelCode',
                    payload: response,
                });
                if (callback) callback(response);
            },
            },

    reducers: {
        deleteByPrimaryKeyForProMenu(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        selectByPrimaryKeyForProMenu(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        insertForProMenu(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        updateForProMenu(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        deleteByMapForProMenu(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        updateByMapForProMenu(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        getOneForProMenu(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        getAllForProMenu(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        queryPageForProMenu(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        countForProMenu(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        insertBatchForProMenu(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        deleteBatchForProMenu(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        updateBatchForProMenu(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        getProMenuTreeByLevelCode(state, action) {
            return {
                ...state,
                menu: action.payload,
            };
        },
    },
};
